﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service : IService
{
    private static Random random = new Random();

    // URI は次の形式です。
    // http://localhost:3258/HeatMapWeb/Services/GetFloors
    [WebGet(ResponseFormat = WebMessageFormat.Json)]
    public Floor[] GetFloors()
    {
        WebOperationContext.Current.OutgoingResponse.Headers[HttpResponseHeader.Expires] = "Wed, 01 Aug 2012 00:00:00 GMT";

        // デバッグ用のコードです。
        //WebOperationContext.Current.OutgoingResponse.ContentType = "text/plain";
        System.Threading.Thread.Sleep(random.Next(10, 500));
        //throw new InvalidOperationException();

        // これはダミーのデータです。
        // 実際には、データベースからデータを取得します。
        return new[]
        {
            new Floor
            {
                Id = "A01", Name = "本社 1F", AccessPoints = new[]
                {
                    new AccessPoint { Id = "1", Name = "柱1", Count = random.Next(0, 50) },
                    new AccessPoint { Id = "2", Name = "柱2", Count = random.Next(0, 50) },
                    new AccessPoint { Id = "3", Name = "柱3", Count = random.Next(0, 50) },
                }
            },
            new Floor
            {
                Id = "A02", Name = "本社 2F", AccessPoints = new[]
                {
                    new AccessPoint { Id = "1", Name = "柱1", Count = 0 },
                    new AccessPoint { Id = "2", Name = "柱2", Count = 2 },
                    new AccessPoint { Id = "3", Name = "柱3", Count = 4 },
                    new AccessPoint { Id = "4", Name = "柱4", Count = 6 },
                    new AccessPoint { Id = "5", Name = "柱5", Count = 8 },
                    new AccessPoint { Id = "6", Name = "柱6", Count = 10 },
                    new AccessPoint { Id = "7", Name = "柱7", Count = 12 },
                    new AccessPoint { Id = "8", Name = "柱8", Count = 14 },
                }
            },
            new Floor
            {
                Id = "A03", Name = "本社 3F", AccessPoints = new[]
                {
                    new AccessPoint { Id = "1", Name = "柱1", Count = 1 },
                    new AccessPoint { Id = "2", Name = "柱2", Count = 5 },
                    new AccessPoint { Id = "3", Name = "柱3", Count = 10 },
                }
            },
            new Floor
            {
                Id = "A04", Name = "本社 4F", AccessPoints = new[]
                {
                    new AccessPoint { Id = "1", Name = "柱1", Count = 2 },
                    new AccessPoint { Id = "2", Name = "柱2", Count = 12 },
                    new AccessPoint { Id = "3", Name = "柱3", Count = 20 },
                }
            },
            new Floor
            {
                Id = "A05", Name = "本社 5F", AccessPoints = new[]
                {
                    new AccessPoint { Id = "1", Name = "柱1", Count = random.Next(0, 20) },
                    new AccessPoint { Id = "2", Name = "柱2", Count = random.Next(0, 20) },
                    new AccessPoint { Id = "3", Name = "柱3", Count = random.Next(0, 20) },
                    new AccessPoint { Id = "4", Name = "柱4", Count = random.Next(0, 20) },
                }
            },
            new Floor
            {
                Id = "A06", Name = "本社 6F", AccessPoints = new[]
                {
                    new AccessPoint { Id = "1", Name = "柱1", Count = random.Next(0, 35) },
                    new AccessPoint { Id = "2", Name = "柱2", Count = random.Next(0, 25) },
                    new AccessPoint { Id = "3", Name = "柱3", Count = random.Next(0, 15) },
                    new AccessPoint { Id = "4", Name = "柱4", Count = random.Next(0, 5) },
                }
            },
        };
    }
}
